package com.gaogzhen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaogzhen.domain.CashRecharge;
import com.gaogzhen.domain.CashRechargeAuditRecord;
import com.gaogzhen.model.CashParam;
import com.gaogzhen.service.CashRechargeService;
import com.gaogzhen.utils.CurrentUser;
import com.gaogzhen.utils.R;
import com.gaogzhen.vo.CashTradeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Administrator
 * @version 1.0
 * @description
 * @date 2022-11-10 11:49
 */
@RestController
@RequestMapping("/cashRecharges")
@Api(tags = "GCN充值控制器")
public class CashRechargeController {

    @Autowired
    private CashRechargeService cashRechargeService;

    @GetMapping("/records")
    @ApiOperation(value = "分页查询GCN充值记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="coinId" ,value = "币种id"),
            @ApiImplicitParam(name ="userId" ,value = "用户id"),
            @ApiImplicitParam(name ="username" ,value = "用户名"),
            @ApiImplicitParam(name ="mobile" ,value = "手机号"),
            @ApiImplicitParam(name ="status" ,value = "状态"),
            @ApiImplicitParam(name ="numMin" ,value = "充值金额下限"),
            @ApiImplicitParam(name ="numMax" ,value = "充值金额上限"),
            @ApiImplicitParam(name ="startTime" ,value = "开始时间"),
            @ApiImplicitParam(name ="endTime" ,value = "终止时间"),
            @ApiImplicitParam(name ="current" ,value = "当前页"),
            @ApiImplicitParam(name ="size" ,value = "每页条目"),
    })
    public R<Page<CashRecharge>> findByPage(
            Page<CashRecharge> page, Long coinId, Long userId, String username, String mobile, Byte status,
            String numMin, String numMax, String startTime, String endTime) {

        return R.ok(cashRechargeService.findByPage(page, coinId, userId, username, mobile, status, numMin, numMax, startTime, endTime));
    }

    @GetMapping("/exportCNYRecharge")
    @ApiOperation(value = "导出GCN充值记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="coinId" ,value = "币种id"),
            @ApiImplicitParam(name ="userId" ,value = "用户id"),
            @ApiImplicitParam(name ="username" ,value = "用户名"),
            @ApiImplicitParam(name ="mobile" ,value = "手机号"),
            @ApiImplicitParam(name ="status" ,value = "状态"),
            @ApiImplicitParam(name ="numMin" ,value = "充值金额下限"),
            @ApiImplicitParam(name ="numMax" ,value = "充值金额上限"),
            @ApiImplicitParam(name ="startTime" ,value = "开始时间"),
            @ApiImplicitParam(name ="endTime" ,value = "终止时间"),
    })
    public void recordsReport( Long coinId, Long userId, String username, String mobile, Byte status,
                               String numMin, String numMax, String startTime, String endTime) {
        cashRechargeService.exportCsv(coinId, userId, username, mobile, status, numMin, numMax, startTime, endTime);
    }

    @PostMapping("/cashRechargeUpdateStatus")
    @ApiOperation(value = "充值审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cashRecharge", value = "cashRecharge json数据")
    })
    public R cashRechargeAudit(@RequestBody CashRechargeAuditRecord auditRecord) {
        cashRechargeService.cashRechargeAudit(CurrentUser.getCurrentUserId(), auditRecord);
        return R.ok();
    }

    @GetMapping("/user/records")
    @ApiOperation(value = "查询当前用户充值记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="status" ,value = "状态"),
            @ApiImplicitParam(name ="current" ,value = "当前页"),
            @ApiImplicitParam(name ="size" ,value = "每页条目"),
    })
    public R<Page<CashRecharge>> findUserCashRecharge(Page<CashRecharge> page, Byte status) {
        return R.ok(cashRechargeService.findUserCashRecharge(CurrentUser.getCurrentUserId(), page, status));
    }

    @PostMapping("/buy")
    @ApiOperation(value = "GCN买入")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="cashParam" ,value = "cashParam json数据"),
    })
    public R<CashTradeVo> buy(@RequestBody @Validated CashParam cashParam) {

        return R.ok(cashRechargeService.buy(CurrentUser.getCurrentUserId(), cashParam));
    }
}
